package com.linq.cool.api.domain;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.linq.cool.api.vo.WeChatLoginUser;
import com.linq.cool.api.vo.WebLoginUser;
import com.linq.cool.common.constants.UserConstants;
import com.linq.cool.common.core.domain.BaseEntity;
import com.linq.cool.common.core.utils.IpUtils;
import com.linq.cool.common.core.utils.ServletUtils;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.math.BigDecimal;
import java.util.Objects;

/**
 * @Author: yqlin
 * @Date: 2021/1/30 21:16
 * @Description: 客户信息表
 * @Version: 1.0.0
 */
@Data
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = true)
@AllArgsConstructor
@NoArgsConstructor
@TableName(value = "beauty_member")
public class BeautyMember extends BaseEntity {
    /**
     * 主键id
     */
    @JsonSerialize(using = ToStringSerializer.class)
    @TableId(value = "id", type = IdType.INPUT)
    private Long id;

    /**
     * 微信唯一openid
     */
    @TableField(value = "openid")
    private String openId;
    /**
     * 手机号码 用户名
     */
    @TableField(value = "phone")
    private String phone;
    /**
     * 密码
     */
    @TableField(value = "`password`")
    private String password;

    /**
     * 身份证号码
     */
    @TableField(value = "id_number")
    private String idNumber;

    /**
     * 真实姓名
     */
    @TableField(value = "real_name")
    private String realName;

    /**
     * 省
     */
    @TableField(value = "province")
    private String province;

    /**
     * 市
     */
    @TableField(value = "city")
    private String city;

    /**
     * 区
     */
    @TableField(value = "county")
    private String county;

    /**
     * 个性签名
     */
    @TableField(value = "note")
    private String note;

    /**
     * 用户昵称
     */
    @TableField(value = "nickname")
    private String nickname;

    /**
     * 地址
     */
    @TableField(value = "address")
    private String address;

    /**
     * 用户邮箱
     */
    @TableField(value = "email")
    private String email;

    /**
     * 用户性别（0:男 1:女 2:未知）
     */
    @TableField(value = "gender")
    private Integer gender;

    /**
     * 头像地址
     */
    @TableField(value = "avatar")
    private String avatar;

    /**
     * 帐号状态（0:正常 1:停用）
     */
    @TableField(value = "`status`")
    private Integer status;

    /**
     * 当前充值金额
     */
    @TableField(value = "amount")
    private BigDecimal amount;

    /**
     * 历史充值金额
     */
    @TableField(value = "history_amount")
    private BigDecimal historyAmount;

    /**
     * 积分
     */
    @TableField(value = "point")
    private BigDecimal point;

    /**
     * 历史积分
     */
    @TableField(value = "history_point")
    private BigDecimal historyPoint;
    /**
     * 删除标志（0:存在 1:删除）
     */
    @TableField(value = "is_deleted")
    private Integer isDeleted;


    public WeChatLoginUser toWeChatLoginUser() {
        return new WeChatLoginUser()
                .setOpenId(openId)
                .setAvatar(avatar)
                .setUserId(id)
                .setPhone(phone)
                .setNickname(nickname)
                .setLoginIp(IpUtils.getIpAddr(Objects.requireNonNull(ServletUtils.getRequest())))
                .setLoginType(UserConstants.StateEnum.LOGIN_TYPE_WECHAT.getCode());
    }

    public WebLoginUser toWebLoginUser() {
        return new WebLoginUser()
                .setAvatar(avatar)
                .setStatus(status)
                .setUserId(id)
                .setGender(gender)
                .setPhone(phone)
                .setPassword(password)
                .setNickname(nickname)
                .setLoginIp(IpUtils.getIpAddr(Objects.requireNonNull(ServletUtils.getRequest())))
                .setLoginType(UserConstants.StateEnum.LOGIN_TYPE_WEB.getCode());
    }
}